/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
/*
 *  ======== gio_dele.c ========
 *
 */

#include <std.h>
#include <mem.h>
#include <que.h>

#include <gio.h>
#include <iom.h>

#include <_gio.h>


/*
 *  ======== GIO_delete ========
 */
Int GIO_delete(GIO_Handle gioChan)
{
    IOM_Packet *packet;

    /* flush and delete low-level device ... */
    if (gioChan->fxns != NULL && gioChan->mdChan != NULL) {
        GIO_flush(gioChan);
        gioChan->fxns->mdDeleteChan(gioChan->mdChan);
    }

    /* delete semaphore or alternate sync object ... */
    if (gioChan->syncObj != NULL) {
        GIO->SEMDELETE(gioChan->syncObj);
    }

    /* free frames ... */
    packet = QUE_get(&gioChan->freeList);
    while (packet != (IOM_Packet *)(&gioChan->freeList)) {
        _GIO_rmPacket(packet);
        packet = QUE_get(&gioChan->freeList);
    }

    /* free GIO object. */
    (Void)MEM_free(0, gioChan, sizeof(GIO_Obj));

    return (IOM_COMPLETED);
}
